<?php


namespace app\utils;


class CurlRequest
{
    function get_json($url)
    {
        $ch = curl_init();

        // 设置URL和相应的选项
        curl_setopt($ch, CURLOPT_URL, $url); //$url设置需要请求的url
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
        //设置请求头
        $headerArray = ["Content-type:application/json;charset='utf8'","Accept:application/json"];
        curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);

        // 抓取URL并把它传递给浏览器
        $result = curl_exec($ch);

        // 关闭cURL资源，并且释放系统资源
        curl_close($ch);

        return $result;
    }
}